﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;

namespace BeniBastanYaratProject.Yonetim
{
    public partial class UrunOzellikIslemleri : System.Web.UI.Page
    {
        DBBaglantiDataContext db = new DBBaglantiDataContext();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;
            urunOzellikDoldur();


        }
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
        protected void Button1_Click(object sender, EventArgs e)
        {
            //ekleme

            string urunOzellik = txtUrunOzellikEkle.Text;
            SqlCommand cmd = new SqlCommand("insert into UrunOzellik (UrunOzellikAdi) values (@urunOzellik)  ", cnn);
            cmd.Parameters.AddWithValue("@urunOzellik", urunOzellik);
            //UrunOzAdi
            cnn.Open();

            cmd.ExecuteNonQuery();


            cnn.Close();

            txtUrunOzellikEkle.Text= "";
            urunOzellikDoldur();
        }
        void urunOzellikDoldur()
        {
            var sorgu = from x in db.UrunOzelliks select x;
            DropDownList1.DataSource = sorgu;
            DropDownList2.DataSource = sorgu;
            DropDownList1.DataBind();
            DropDownList2.DataBind();
        }
        protected void btnGuncelle_Click(object sender, EventArgs e)
        {
            string yeniUrunOzAdi = txtUrunOzellikGuncelle.Text;
            int urunOzellikId = Convert.ToInt32(DropDownList1.SelectedValue);
            SqlCommand cmd = new SqlCommand("UPDATE UrunOzellik SET UrunOzellikAdi = @yeniUrunOzAdi WHERE UrunOzellikId = @urunOzellikId", cnn);
            cmd.Parameters.AddWithValue("@yeniUrunOzAdi", yeniUrunOzAdi);
            cmd.Parameters.AddWithValue("@urunOzellikId", urunOzellikId);
            cnn.Open();

            cmd.ExecuteNonQuery();

            cnn.Close();
            urunOzellikDoldur();
            
        }

        protected void btnSil_Click(object sender, EventArgs e)
        {
            int urunOzellikId = Convert.ToInt32(DropDownList2.SelectedValue);

            SqlCommand cmd = new SqlCommand("delete from UrunOzellik where UrunOzellikID=@urunOzellikId ", cnn);
            cmd.Parameters.AddWithValue("@urunOzellikId", urunOzellikId);

            cnn.Open();

            cmd.ExecuteNonQuery();

            cnn.Close();
            urunOzellikDoldur();
        }

       

        
    }
}